/*
 * @Description: ...
 * @Author: yangli 121029539@qq.com
 * @Date: 2025-01-18 09:20:44
 * @LastEditTime: 2025-02-12 16:12:34
 * @LastEditors: yangli 121029539@qq.com
 * @FilePath: \uniapp\src\stores\theme.ts
 */
import { getDecorate } from '@/api/shop'
import { generateVars } from '@/utils/theme'
import { defineStore } from 'pinia'

interface ThemeStore {
    primaryColor: string
    minorColor: string
    btnColor: string
    navColor: string
    navBgColor: string
    vars: string
}
export const useThemeStore = defineStore({
    id: 'themeStore',
    state: (): ThemeStore => ({
        primaryColor:  '#FE7906',
        minorColor: '',
        btnColor: 'white',
        navColor: '#000000',
        navBgColor: '#ffffff',
        vars: ''
    }),
    actions: {
        async getTheme() {
   
            const data = await getDecorate({
                id: 5
            })
            /**
             * buttonColor: "white"
                navigationBarColor: "#2F80ED"
                themeColor1: "#2F80ED"
                themeColor2: "#56CCF2"
                themeColorId: 1
                topTextColor: "white"
             */
            const {
                themeColor1,
                themeColor2,
                buttonColor,
                navigationBarColor,
                topTextColor
            } = JSON.parse(data.data)
            console.log('-data.data--',JSON.parse(data.data))
            // this.primaryColor = themeColor1
            // this.minorColor = themeColor2
            // this.btnColor = buttonColor
            // this.navColor = topTextColor === 'white' ? '#ffffff' : '#000000'
            // this.navBgColor = navigationBarColor || themeColor1
            // this.vars = generateVars(
            //     {
            //         primary: themeColor1
            //     },
            //     {
            //         '--color-minor': themeColor2,
            //         '--color-btn-text': buttonColor
            //     }
            // )
            // #FE7906 #c455ff
            this.primaryColor = '#ed722f' 
            this.minorColor = '#FE7906' 
            this.btnColor = '#1E1D2E' 
            this.navColor = '#000000'
            this.navBgColor = '#fff' 
            this.vars = generateVars(
                {
                    primary: '#ed722f'
                },
                {
                    '--color-minor': '#FE7906' ,
                    '--color-btn-text': '#1E1D2E' 
                }
            )
        },
        setTheme(color: string) {
            this.primaryColor = color
        }
    }
})
